<template>
	<view class="container">
		<view class="step" v-show="intActive==0">
			<view class="c-input">
				<input type="number" @input="onRegMobile" v-model="regMobile" placeholder="请输入手机号" />
			</view>
			<view class="c-input c-pos">
				<input type="number" @input="onRegCode" v-model="regCode" placeholder="请输入验证码" />
				<button type="primary" :disabled="blnDisabled_code" size="mini" class="c-input-btn c-regcode" @click="onGetRegCode">获取验证码</button>
			</view>
			<view class="c-input">
				<button type="primary" :disabled="blnDisabled_btn" class="c-input-btn" @click="onChkCode">同意协议并注册</button>
			</view>
			<view class="c-bottom-tip">
				<text>已阅读并同意：</text>
				<navigator url="">许可协议</navigator>
			</view>
		</view>
		<view class="step" v-show="intActive==1">
			<view class="c-input">
				<input type="text" @input="onRegRealName" v-model="regRealName" placeholder="请输入真实姓名" />
			</view>
			<view class="c-input">
				<input type="password" @input="onRegPassWord" v-model="regPassWord" placeholder="请输入密码" />
			</view>
			<view class="c-input">
				<editor class="c-editor" @input="onRegIntro" v-model="regIntro" placeholder="请说明所属单位和部分"></editor>
			</view>
			<view class="c-input">
				<button type="primary" :disabled="blnDisabled_reg" class="c-input-btn" @click="onSubmitRegInfo">确认提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	let pageApp = getApp();
	export default {
		data() {
			return {
				regMobile: "",
				regCode: "",
				regRealName: "",
				regPassWord: "",
				regToken: "",
				regIntro: "",
				blnDisabled_btn: true,
				blnDisabled_code: true,
				blnDisabled_reg: true,
				blnIsSend: false,
				intActive: 0
			}
		},
		methods: {
			onRegMobile(e) {
				if (!this.blnIsSend) {
					this.blnDisabled_code = this.checkIsEmpty(this.regMobile, "000000");
				}
				this.blnDisabled_btn = this.checkIsEmpty(this.regMobile, this.regCode);
			},
			onRegCode(e) {
				if (!this.blnIsSend) {
					this.blnDisabled_code = this.checkIsEmpty(this.regMobile, "000000");
				}
				this.blnDisabled_btn = this.checkIsEmpty(this.regMobile, this.regCode);
			},
			onRegRealName(e) {
				this.blnDisabled_reg = this.checkIsEmpty(this.regRealName, this.regPassWord);
			},
			onRegPassWord(e) {
				this.blnDisabled_reg = this.checkIsEmpty(this.regRealName, this.regPassWord);
			},
			onRegIntro(e) {
				this.regIntro = e.detail.text;
			},
			onGetRegCode(e) {
				// 数据基础验证
				if (this.checkMobileCode(this.regMobile)) {
					uni.showToast({
						icon: "none",
						title: "手机号格式有误！"
					})
				} else {
					this.blnDisabled_code = true;
					uni.showToast({
						icon: "none",
						title: "验证码正在发送中..."
					})
					// 准备请求数据
					let apiData = {
						url: pageApp.globalData.url + '/GetMessageCheck',
						data: {
							"Mobile": this.regMobile
						},
						success: (d) => {
							if (d.data.code == "001") {
								this.blnIsSend = true;
								uni.showToast({
									icon: "none",
									title: "验证码已发送"
								})
							} else {
								uni.showToast({
									icon: "none",
									title: d.data.msg
								})
							}
						}
					}
					// 发送数据请求
					this.vjAjaxData(apiData);
				}
			},
			onChkCode(e) {
				// 基础验证
				if (this.regCode.trim().length != 6) {
					uni.showToast({
						icon: "none",
						title: "验证码长度有误！"
					})
				} else {
					// 准备请求数据
					let apiData = {
						url: pageApp.globalData.url + '/Regist_App1',
						data: {
							"Mobile": this.regMobile,
							"CheckCode": this.regCode
						},
						method: "POST",
						success: (d) => {
							if (d.data.code == "001") {
								uni.showToast({
									title: "验证成功",
									success: () => {
										this.intActive = 1;
										uni.setNavigationBarTitle({
											title: "完善注册信息-用户注册",
											success: () => {
												this.regToken = d.data.data.CheckToken;
											}
										})
									}
								})
							} else {
								uni.showToast({
									icon: "none",
									title: d.data.msg
								})
							}
						}
					}
					// 发送数据请求
					this.vjAjaxData(apiData);
				}
			},
			onSubmitRegInfo(e) {
				if (this.regPassWord.trim().length >= 6) {
					// 准备请求数据
					let apiData = {
						url: pageApp.globalData.url + "/Regist_App2",
						data: {
							"LoginName": this.regMobile,
							"UserName": this.regRealName,
							"PasswordSalt": this.regPassWord,
							"LoginNote": this.regIntro,
							"Mobile": this.regMobile,
							"CheckToken": this.regToken
						},
						method: "POST",
						success: (d) => {
							if (d.data.code == "001") {
								uni.showToast({
									title: "注册成功",
									success: () => {
										// 返回登录页
										setTimeout(() => {
											uni.navigateTo({
												url: "./login/login"
											})
										}, 3000)
									}
								})
							} else {
								uni.showToast({
									icon: "none",
									title: d.data.msg
								})
							}
						}
					}
					// 发送数据请求
					this.vjAjaxData(apiData);
				} else {
					uni.showToast({
						icon: "none",
						title: "密码必须大于6位"
					})
				}
			}
		}
	}
</script>

<style>
	.ql-editor.ql-blank:before {
		font-style: normal;
	}

	.c-editor {
		border: solid 2rpx #F1F5F6;
		padding: 16rpx;
	}
</style>
